function Group(){
    var groupname;
    var id;
    var matches = [];
    var teams;
    var groupOrderId;
    
    this.setGroupName = function(name){
        groupname = name;
    };
    this.getGroupName = function(){
        return groupname;
    };
    
    this.setGroupId = function(groupid){
        id = groupid;
    }
    this.getGroupId = function(){
        return id;
    }
    
    this.setGroupOrderId = function(groupid){
        groupOrderId = groupid;
    }
    this.getGroupOrderId = function(){
        return groupOrderId;
    }
    
    this.setMatches = function(mat){
        matches = mat;
    }
    this.getAllMatches = function(){
        return matches;
    }
    this.addMatch = function(match){
        matches.push(match);
    }

    this.setTeams = function(newTeams){
        teams = newTeams;
    }
    this.getAllTeams = function(){
        return teams;
    }
    this.addTeam = function(team) {
        teams.push(team);
    }
}

/**
 * Get score for a team.
 * @param team name of the team
 * @return score
 * */
Group.prototype.getScoreForTeam = function(team) {
    var score = 0;
    var matches = this.getAllMatches();
    for (i in matches) {
        var match = matches[i];

        var points = 0;
        if (match.getTeam1() == team){
            points = match.getTeam1Points();
        }else if(match.getTeam2() == team) {
            points = match.getTeam2Points();
        }
        points = points < 0 ? 0 : points;
        score += points;
    }

    return score;
}

Group.prototype.getDatabaseObject = function(){
    return {
        id      : this.getGroupId(),
        name    : this.getGroupName(),
        groupOrderId : this.getGroupId(),
    }
}

Group.prototype.convertToBusinessObject = function(dbObject){
    this.setGroupId(dbObject.id);
    this.setGroupName(dbObject.name);
    this.setGroupOrderId(dbObject.groupOrderId);
}